package com.ymatou.operate.trading.api.service;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;
/**
*创建订单(新)接口Call
*FreeMaker Template自动生成代码
*/
public class PlaceOrderCall extends YmatouBaseCall{
	private static String opurl ="api/Buyer/PlaceOrder";
	
	public PlaceOrderCall() {
		super(EnvSetup.getSystemUrl("api_order_operate"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	/**
     * 获取Code
     * 
     * @return
     */
    public String getCode() {
        String Code = null;
        try {
            Code = new JSONObject(getReturnData()).getString("Code");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Code;
    }

    /**
     * 获取BCode
     * 
     * @return
     */
    public String getBCode() {
        String BCode = null;
        try {
            BCode = new JSONObject(getReturnData()).getString("BCode");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return BCode;
    }

    /**
     * 获取Msg
     * 
     * @return
     */
    public String getMsg() {
        String BCode = null;
        try {
            BCode = new JSONObject(getReturnData()).getString("Msg");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return BCode;
    }

    /**
     * 获取Data
     * 
     * @return
     */
    public JSONObject getData() {
        JSONObject Data = null;
        try {
            Data = new JSONObject(getReturnData()).getJSONObject("Data");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Data;
    }

    /**
     * 获取TradingId
     * 
     * @return
     */
    public int getTradingId() {
        int TradingId = 0;
        try {
            TradingId = getData().getInt("TradingId");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return TradingId;
    }

    /**
     * 获取OrderIds订单列表
     * 
     * @return
     */
    public JSONArray getOrderIds() {
        JSONArray OrderIds = null;
        try {
            OrderIds = getData().getJSONArray("OrderIds");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return OrderIds;
    }
}